package ThreadDome;
public class Dome9 {
    private static boolean isRunning = true;

    public static void main(String[] args) {
        Thread t = new Thread(()->{
            while(isRunning) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("t线程使用中...");
            }
            System.out.println("t线程结束.");
        });
        t.start();
        try{
            Thread.sleep(3000);
        }catch (InterruptedException e) {
            throw new RuntimeException();
        }
        //3s后修改isRunning的值使线程结束
        System.out.println("main线程控制t结束");
        isRunning = false;
    }
}
